# Except build system developers, others should not edit this file.
# User can create a user_config.cmake in the parent directory and overide the
# settings in this file.
# All config items can be overidden in user_config.cmake file. 
# user_config.cmake will be invoke before init sync provider.
# normal user settings under usr/ folder will be invoke after all system
# actions, but before calling j_add_projects(projets)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if (NOT DEFINED j_external_lib_root)
endif()

if (CMAKE_SIZEOF_VOID_P MATCHES 8)
	set(j_architecture x64)
	set(j_x64 TRUE)
elseif(CMAKE_SIZEOF_VOID_P MATCHES 4)
	set(j_architecture x86)
	set(j_x86 TRUE)
else()
	message( CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
	j_assert("Unsupport architecture " FALSE)
endif()

if (APPLE)
	set (j_lib_prefix "lib")
	set (j_static_lib_ext ".a")
	set (j_shared_lib_ext ".dylib")
	set (j_link_lib_ext ${j_shared_lib_ext})
	if (${j_platform} STREQUAL "mac")
		set (j_os_name mac)
		set (CMAKE_OSX_SYSROOT macosx)
	else()
		set (j_os_name ios)
		set (CMAKE_OSX_SYSROOT iphoneos)
	endif()
	#set_property(GLOBAL PROPERTY XCODE_ATTRIBUTE_SUPPORTED_PLATFORMS ${j_supported_platforms})
elseif (UNIX)
	set (j_lib_prefix "lib")
	set (j_static_lib_ext ".a")
	set (j_shared_lib_ext ".so")
	set (j_link_lib_ext ${j_shared_lib_ext})
	set (j_os_name linux)
elseif(WIN32)
	set (j_lib_prefix "")
	set (j_static_lib_ext ".lib")
	set (j_shared_lib_ext ".dll")
	set (j_link_lib_ext ${j_static_lib_ext})
	set (j_os_name win)
endif()

if (WIN32)
	if (MSVC_VERSION LESS "1500")
		j_assert("Unsupport MSVC version: ${MSVC_VERSION}" FALSE)
	elseif(MSVC_VERSION LESS "1600")
		set(j_compiler_name vc90)
	elseif(MSVC_VERSION LESS "1700")
		set(j_compiler_name vc100)
	elseif(MSVC_VERSION LESS "1800")
		set(j_compiler_name vc110)
	elseif(MSVC_VERSION LESS "1900")
		set(j_compiler_name vc120)
	elseif(MSVC_VERSION LESS "2000")
		set(j_compiler_name vc140)
	elseif()
		j_assert("Unsupport architecture " FALSE)
	endif()
elseif(UNIX)
	if(APPLE)
		#string(REGEX REPLACE "^([0-9]+\\.[0-9]+\\.[0-9]+).*$" "clang_\\1"
		string(REGEX REPLACE "^([0-9]+)\\..*$" "clang\\1"
			        j_compiler_name
				   ${CMAKE_CXX_COMPILER_VERSION} )
	else()
		set(j_compiler_name gcc${CMAKE_CXX_COMPILER_VERSION})
		#set(j_compiler_name gcc_4.7)
	endif()
endif()

set (j_compiler_name_for_external ${j_compiler_name})

if (WIN32)
	set(j_3rd_command do_nothing.bat)
	set(j_external_project_command do_nothing.bat)
else()
	set(j_3rd_command do_nothing.sh)
	set(j_external_project_command do_nothing.sh)
endif()

set(j_3rd_command_type  COMMAND)

string(TOLOWER ${CMAKE_BUILD_TYPE} j_config)


set(CMAKE_DEBUG_POSTFIX "-d")

set(j_identified_path "${j_os_name}/${j_compiler_name}/${j_architecture}")
set(j_recognized_path "${j_identified_path}/${j_config}")
string(TOLOWER ${j_recognized_path} j_recognized_path)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Weffc++ -Werror -g -fvisibility=hidden -fvisibility-inlines-hidden")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -Wall -Weffc++ -Werror -g -fvisibility=hidden -fvisibility-inlines-hidden -std=c++11 -stdlib=libc++")
	if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wno-unused-local-typedef")
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedef")
	endif()
	j_set_path(j_default_runtime_property_path "${j_project_output_root_dir}/bin/${j_identified_path}")
	j_set_path(j_default_archive_property_path "${j_project_output_root_dir}/lib/${j_identified_path}")
	j_set_path(j_default_library_property_path "${j_project_output_root_dir}/bin/${j_identified_path}")
	j_set_path(j_default_deploy_property_path "${j_project_output_root_dir}/../run/${j_identified_path}")
	j_set_path(j_default_sym_property_path "${j_project_output_root_dir}/sym/${j_identified_path}")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -Werror -Wno-unused-local-typedefs -g -fvisibility=hidden -fvisibility-inlines-hidden")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wall -Werror -Wno-unused-local-typedefs -g -fvisibility=hidden -fvisibility-inlines-hidden")
	set(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -pie")
	set(CMAKE_SHARED_LINKER_FLAGS  "${CMAKE_SHARED_LINKER_FLAGS} -pie")
	set(CMAKE_MODULE_LINKER_FLAGS  "${CMAKE_MODULE_LINKER_FLAGS} -pie")
	j_set_path(j_default_runtime_property_path "${j_project_output_root_dir}/bin/${j_recognized_path}")
	j_set_path(j_default_archive_property_path "${j_project_output_root_dir}/lib/${j_recognized_path}")
	j_set_path(j_default_library_property_path "${j_project_output_root_dir}/bin/${j_recognized_path}")
	j_set_path(j_default_deploy_property_path "${j_project_output_root_dir}/../run/${j_recognized_path}")
	j_set_path(j_default_sym_property_path "${j_project_output_root_dir}/sym/${j_recognized_path}")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
	# using Intel C++
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS /Oi /nologo /GS /Zi /errorReport:prompt /MP")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS /Oi /nologo /GS /Zi /errorReport:prompt /MP")
	set(j_disabled_warning "${j_disabled_warning} 
			/wd4512" 			# 'class' : assignment operator could not be generated
		) 
	if (j_compiler_name STREQUAL "vc14")
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc ${j_disabled_warning}")
	else()
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc ${j_disabled_warning}")
	endif()
	j_set_path(j_default_runtime_property_path "${j_project_output_root_dir}/bin/${j_identified_path}")
	j_set_path(j_default_archive_property_path "${j_project_output_root_dir}/lib/${j_identified_path}")
	j_set_path(j_default_library_property_path "${j_project_output_root_dir}/bin/${j_identified_path}")
	j_set_path(j_default_deploy_property_path "${j_project_output_root_dir}/../run/${j_identified_path}")
	j_set_path(j_default_sym_property_path "${j_project_output_root_dir}/sym/${j_identified_path}")
endif()

j_set_path(j_default_deploy_path "${j_project_output_root_dir}/../run/${j_recognized_path}")
j_set_path(j_default_archive_path "${j_project_output_root_dir}/lib/${j_recognized_path}")
j_set_path(j_default_runtime_path "${j_project_output_root_dir}/bin/${j_recognized_path}")
j_set_path(j_default_sym_path "${j_project_output_root_dir}/sym/${j_recognized_path}")
j_set_path(j_default_generated_path "${j_project_output_root_dir}/generated")

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

if(APPLE)
	set(CMAKE_MACOSX_RPATH ON)
    set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10)
    if ("${j_config}" STREQUAL "release")
        add_definitions(-D_LIBCPP_DEBUG2=0)
    endif()
endif()

if(MSVC)
	add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
	if (j_unicode_enabled)
		add_definitions(-DUNICODE -D_UNICODE)
	endif()
endif()

if ("${j_compiler}" STREQUAL "")
	string(TOLOWER "${CMAKE_CXX_COMPILER_ID}" compiler_id)
	set(j_compiler ${compiler_id} )
endif()

if ("${j_compiler_version}" STREQUAL "")
	string(REGEX REPLACE "^([0-9]+\\.[0-9]+).*$" "\\1" compiler_version "${CMAKE_CXX_COMPILER_VERSION}" )
	set(j_compiler_version ${compiler_version} )
endif()

if ("${j_pkg_os}" STREQUAL "" AND NOT "${j_platform}" STREQUAL "")
	set(j_pkg_os ${j_platform})
endif()
if ("${j_pkg_arch}" STREQUAL "" AND NOT "${j_architecture}" STREQUAL "")
	if ("${j_architecture}" STREQUAL "x86")
		set(j_pkg_arch "intel32")
	elseif ("${j_architecture}" STREQUAL "x64")
		set(j_pkg_arch "intel64")
	else()
		set(j_pkg_arch ${j_architecture})
	endif()
endif()
if ("${j_pkg_config}" STREQUAL "" AND NOT "${j_config_dir}" STREQUAL "")
	set(j_pkg_config ${j_config_dir})
endif()
if ("${j_pkg_compiler}" STREQUAL "" AND NOT "${j_compiler}" STREQUAL "")
	set(j_pkg_compiler ${j_compiler_name})
endif()
set(j_pkg_extension ".zip")
